<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            容器查询
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">条码</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请扫描条码" id="trayyinfoid" value="" onclick="getIdSelector();">
                    </div>
                </div>
            </li>
        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="getTrayInfo()" id="submitButton">查询</div>
        <div style="background-color:white; height: 100%;width: 100%;margin-top:2%;margin-bottom:20%;" id="tbodyHtml">
        </div>
        <!-- <div style="background-color:white; height: 100%;width: 100%;margin-top:3%;border:solid 1px #D3D3D3;display:none;margin-bottom:50px;"
            id="tableDiv">
            <table class="table" style='width:100%; font-size:14px;' id="table">
                <tbody>
                    <tr>
                        <td style="width:20%;text-align:right;">供&nbsp&nbsp应&nbsp&nbsp商:</td>
                        <td id="ctBarcodetital"></td>
                    </tr>
                    <tr>
                        <td style="width:20%;text-align:right;">仓&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp库:</td>
                        <td id="cellCodetital"></td>
                    </tr>
                    <tr>
                        <td style="width:20%;text-align:right;">库&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp位:</td>
                        <td id="ext13tital"></td>
                    </tr>
                    <tr>
                        <td style="width:20%;text-align:right;">物&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp料:</td>
                        <td id="qtytital"></td>
                    </tr>
                    <tr>
                        <td style="width:20%;text-align:right;">规&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp格:</td>
                        <td id="ctBarcodetital"></td>
                    </tr>
                    <tr>
                        <td style="width:20%;text-align:right;">批&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp次:</td>
                        <td id="ctBarcodetital"></td>
                    </tr>
                    <tr>
                        <td style="width:20%;text-align:right;">数&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp量:</td>
                        <td id="ctBarcodetital"></td>
                    </tr>
                    <tr>
                        <td style="width:20%;text-align:right;">状&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp态:</td>
                        <td id="ctBarcodetital"></td>
                    </tr>
                    <tr>
                        <td style="width:20%;text-align:right;">条码种类:</td>
                        <td id="ctBarcodetital"></td>
                    </tr>
                </tbody>
            </table>
        </div> -->
    </div>
    <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/clickThrottle.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var html = ""; //全局拼接HTML
    var arrSave = [];
    var array = new Array();
    // var delArray = new Array();
    //初始化查询仓库下拉框
    apiready = function () {

        $("#trayyinfoid").focus();
        idSelector = "trayyinfoid";
        //查询条码解析规则
        initScanRule();

    }

    //查询扫描规则
    function initScanRule() {
        var serverUrl = localStorage.getItem('serverUrl');
        var un = localStorage.getItem("un");
        var url = serverUrl + "/app/getTmScanRule";
        var data = {
            values: {
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    scanRule = myobj.scanRule
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }
    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {

            if (idSelector == 'trayyinfoid') {
                //容器条码
                $("#trayyinfoid").val(ret);
                getTrayInfo();
            }
        });
    }

    //条码监听回车事件
    $("#trayyinfoid").on('keypress', function (e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            if (tm != null && tm != "" && tm != undefined) {
                console.log(tm);
                $("#trayyinfoid").val(tm);
                getTrayInfo();
            }

        }
    });

    function getTrayInfo() {
        if (!clickThrottle()) {
            return;
        } 
        const submitButton = document.getElementById('submitButton');

        submitButton.style.pointerEvents = "none"
        api.showProgress({
            title: '查询中...',
        });
        var sm = $("#trayyinfoid").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/doSearchQueries";
        var data = {
            values: {
                sm: sm,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    api.hideProgress();
                    submitButton.style.pointerEvents = "auto"
                    var html = "";
                    var category = myobj.category;

                    if (myobj.category == "箱") {
                        html += "<div id = '' class='aaui-btn-info aui-btn-block' style='margin-bottom: 10px;color: black !important;background-color: #addbef !important;height: 200px;padding: 0.2rem 0.2rem;font-size: 0.7rem;'>";
                        //html += "<div id = '' class='aaui-btn-info aui-btn-block' style='margin-bottom: 10px;color: black !important;background-color: #addbef !important;height: 200px;padding: 0.2rem 0.2rem;font-size: 0.7rem;'>";
                        html += "<tr style='width:100%;'><td style='width:30%;'>供应商：</td><td  id='cellCodetital' ' colspan='3'>" + myobj.ysupplierCode + "</td></tr></br>";
                        html += "<tr style='width:100%;'><td style='width:30%;'>仓库：</td><td  id='cellCodetital' ' colspan='3'>" + myobj.workCenterCode + ":" + myobj.workCenterName + "</td></tr></br>";
                        html += "<tr style='width:100%;'><td style='width:30%;'>库位：</td><td  id='cellCodetital' ' colspan='3'>" + myobj.workCellCode + ":" + myobj.workCellName + "</td></tr></br>";
                        html += "<tr style='width:100%;'><td style='width:30%;'>物料：</td><td  id='cellCodetital' ' colspan='3'>" + myobj.mrlCode + ":" + myobj.mrlName + "</td></tr></br>";
                        html += "<tr style='width:100%;'><td style='width:30%;'>规格：</td><td  id='cellCodetital' ' colspan='3'>" + myobj.drawing + "</td></tr></br>";
                        html += "<tr style='width:100%;'><td style='width:30%;'>批次：</td><td  id='cellCodetital' ' colspan='3'>" + myobj.lotCode + "</td></tr></br>";
                        html += "<tr style='width:100%;'><td style='width:30%;'>数量：</td><td  id='cellCodetital' ' colspan='3'>" + myobj.qty + "</td></tr></br>";
                        html += "<tr style='width:100%;'><td style='width:30%;'>状态：</td><td  id='cellCodetital' ' colspan='3'>" + myobj.status + "</td></tr></br>";
                        html += "<tr style='width:100%;'><td style='width:30%;'>条码种类：</td> <td  id='cellCodetital' ' colspan='3'>" + myobj.category + "</td></tr></br>";
                        html += "</tr>";
                        html += "</div>";
                    } else if (myobj.category == "容器") {
                        html += "<div id = '' class='aaui-btn-info aui-btn-block' style='border-radius: 10px;margin-bottom: 10px;color: black !important;background-color: #D0D0D0 !important;height: 90px;padding: 0.2rem 0.2rem;font-size: 0.7rem;'>";
                        html += "<tr style='width:100%;'><td style='width:30%;'>仓库：</td> <td  id='cellCodetital' ' colspan='3'>" + myobj.workCenterCode + ":" + myobj.workCenterName + "</td></tr></br>";
                        html += "<tr style='width:100%;'><td style='width:30%;'>库位：</td> <td  id='cellCodetital' ' colspan='3'>" + myobj.workCellCode + ":" + myobj.workCellName + "</td></tr></br>";
                        html += "<tr style='width:100%;'><td style='width:30%;'>状态：</td> <td  id='cellCodetital' ' colspan='3'>" + myobj.status + "</td></tr></br>";
                        html += "<tr style='width:100%;'><td style='width:30%;'>条码种类：</td> <td  id='cellCodetital' ' colspan='3'>" + myobj.category + "</td></tr></br>";
                        html += "</div>";
                        var list = myobj.list
                        for (var i = 0; i < list.length; i++) {
                            html += "<div id = '' class='aaui-btn-info aui-btn-block' style='border-radius: 10px;margin-bottom: 10px;color: black !important;background-color: #addbef !important;height: 130px;padding: 0.2rem 0.2rem;font-size: 0.7rem;display:flex;align-items:center'>";
                            if (list[i].ysupplierCode == null) {
                                html += "<tr style='width:100%;'><td style='width:30%;'>供应商：</td> <td  id='cellCodetital' ' colspan='3'>" + "" + "</td></tr></br>";
                            } else {
                                html += "<tr style='width:100%;'><td style='width:30%;'>供应商：</td> <td  id='cellCodetital' ' colspan='3'>" + list[i].ysupplierCode + "</td></tr></br>";
                            }
                            //html += "<tr style='width:100%;'><td style='width:30%;'>供应商：</td> <td  id='cellCodetital' ' colspan='3'>" + list[i].ysupplierCode + "</td></tr></br>";
                            
                            html += "<tr style='width:100%;'><td style='width:30%;'>物料：</td> <td  id='cellCodetital' ' colspan='3'>" + list[i].mrlCode + ":" + list[i].mrlName + "</td></tr></br>";
                            html += "<tr style='width:100%;'><td style='width:30%;'>规格：</td> <td  id='cellCodetital' ' colspan='3'>" + list[i].drawing + "</td></tr></br>";
                            html += "<tr style='width:100%;'><td style='width:30%;'>批次：</td> <td  id='cellCodetital' ' colspan='3'>" + list[i].lotCode + "</td></tr></br>";
                            html += "<tr style='width:100%;'><td style='width:30%;'>数量：</td> <td  id='cellCodetital' ' colspan='3'>" + list[i].qty + "</td></tr></br>";
                           
                            html += "</div>";
                        }

                        
                    }
                    $api.html($api.byId("tbodyHtml"), html);
                    //失败
                } else if (myobj.code == "1") {
                    api.hideProgress();
                    submitButton.style.pointerEvents = "auto"
                    $("#trayyinfoid").val("");
                    $("#trayyinfoid").select();
                    idSelector = "trayyinfoid";

                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
                    submitButton.style.pointerEvents = "auto"
                $("#trayyinfoid").val("");
                $("#trayyinfoid").select();
                idSelector = "trayyinfoid";
                alert("连接超时，请耐心等待");
            }
        });
    }

    //扫描之后箱码解析
    function tmSplit(sm) {
        $("#tm").val(sm);
        //直接解析
        if (scanRule == "old") {

            //本地解析
            localAnalyze(sm);

        } else {

            //后台解析
            postAnalyze(sm);
        }
    }

    //本地解析
    function localAnalyze(sm) {
        var arr = sm.split(",");
        $("#supplierCode").val(arr[0]);
        $("#mrlCode").val(arr[1]);
        $("#qty").val(arr[2]);
        $("#lotCode").val(arr[3]);
        $("#tmID").val(arr[4]);
        $("#boxnum").val(arr[9]);
        //箱号选中
        $("#tm").select();

    
    }

    //后台解析箱码
    function postAnalyze(sm) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/analysisBarCodeCommon";
        var data = {
            values: {
                tm: sm, //箱码
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {

                    var map = myobj.data;
                    for (var key in map) {
                        $("#" + key).val(map[key]);
                    }

                    getTrayInfo()
                } else if (myobj.code == '1') {

                    $("#tm").val("");
                    $("#tm").select();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                // alert(JSON.stringify(err));
                alert("连接超时，请耐心等待");
            }
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>